package org.example.utils;

import cn.hutool.core.util.StrUtil;

/**
 * 驼峰名称转换
 */
public class HumpUtils {

    private static String execute(String value, int ignoreIndex) {
        StringBuffer buffer = new StringBuffer();
        if (value.contains("_")) {
            String[] s = value.split("_");
            for (int i = 0; i < s.length; i++) {
                if (i != ignoreIndex) {
                    buffer.append(StrUtil.format("{}{}", s[i].substring(0, 1).toUpperCase(), s[i].substring(1)));
                }
            }
        } else {
            buffer.append(value);
        }
        return buffer.toString();
    }

    public static String className(String value) {
        return execute(value.toLowerCase(), -1);
    }

    public static String fieldName(String value) {
        return execute(value.toLowerCase(), 0);
    }
}
